package com.vonchange.utils.tpl.help;

import java.io.File;
import java.io.IOException;
import java.util.HashMap;
import java.util.Map;

import com.fasterxml.jackson.core.type.TypeReference;
import com.vonchange.utils.encrypt.MD5Util;
import com.vonchange.utils.file.FileUtils;
import com.vonchange.utils.json.JsonUtil;

public class ReadJsonToMap {
	public static Map<String, Map<String, String>> cache = new HashMap<String, Map<String, String>>();
	public static Map<String, String> read(File file) {
		String path = file.getPath();
		String md = MD5Util.getMD5(path + file.lastModified());
		if (null == cache.get(md)) {
			String configJson = null;
			try {
				configJson = FileUtils.readFileToString(file);
			} catch (IOException e) {
				// TODO Auto-generated catch block
				e.printStackTrace();
			}
			Map<String, String> configMap = JsonUtil.fromJson(configJson,new TypeReference<Map<String, String>>() {
			});
			cache.put(md, configMap);
		}
		return cache.get(md);
	}
}
